package com.yanqu.road.entity.activity.ruishou;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.sql.Types;
import java.util.HashMap;
import java.util.Map;

@FieldTypeAnnotation(tableName = "t_u_activity_rui_shou_user_data")
public class RuiShouUserData extends DataObject {

    @FieldTypeAnnotation(desc = "活动ID", select = true, update = true)
    private int activityId;

    @FieldTypeAnnotation(desc = "用户ID", select = true, update = true)
    private long userId;

    @FieldTypeAnnotation(desc = "击杀怪物累计", sqlType = Types.LONGVARCHAR)
    private Map<Integer, Integer> killMonsterCntMap = new HashMap<>();

    @FieldTypeAnnotation(desc = "积分")
    private long score;


    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setUpdateOption();
        }
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            setUpdateOption();
        }
    }

    public Map<Integer, Integer> getKillMonsterCntMap() {
        return killMonsterCntMap;
    }

    public void setKillMonsterCntMap(Map<Integer, Integer> killMonsterCntMap) {
        if (killMonsterCntMap == null) {
            return;
        }
        this.killMonsterCntMap = killMonsterCntMap;
        setUpdateOption();
    }

    public long getScore() {
        return score;
    }

    public void setScore(long score) {
        if (this.score != score) {
            this.score = score;
            setUpdateOption();
        }
    }

    /**
     * 击杀怪物计数
     */
    public void addKillMonsterCnt(int monsterId) {
        killMonsterCntMap.put(monsterId, killMonsterCntMap.getOrDefault(monsterId, 0) + 1);
        setUpdateOption();
    }

    /**
     * 获取击杀总数
     */
    public int getAllKillMonsterCnt() {
        return killMonsterCntMap.values().stream().mapToInt(value -> value).sum();
    }
}
